﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Threading.Tasks;

namespace TPLSampleWPF
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            button1.Content = "Processing...";
            button1.IsEnabled = false;

            Task t = Task.Factory.StartNew(() =>
                {
                    System.Threading.Thread.Sleep(5000);

                }).ContinueWith(o => 
                {
                    button1.Content = "Process";
                    button1.IsEnabled = true; 

                },TaskScheduler.FromCurrentSynchronizationContext()); 
        }

        private void button2_Click(object sender, RoutedEventArgs e)
        {
            button2.Content = "Processing...";
            button2.IsEnabled = false;

            Task t = Task.Factory.StartNew(() =>
            {
                System.Threading.Thread.Sleep(5000);

            }).ContinueWith(o =>
            {
                button2.Content = "Process";
                button2.IsEnabled = true;

            }, TaskScheduler.FromCurrentSynchronizationContext()); 

        }
    }
}
